package com.bbx.taxi.client.Task;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Handler;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.official.passanger.Officail_ComboBuild;
import com.bbx.api.sdk.model.official.passanger.Official_ORGBuild;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Combo;
import com.bbx.api.sdk.model.official.passanger.Return.Official_ORG;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Officail_ComboNet;
import com.bbx.api.sdk.net.official.passanger.Official_ORGNet;
import com.bbx.api.sdk.net.official.passanger.Official_StarNet;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Task.BaseAsyncTask;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.official.R;

/** 
 * @Path com.bbx.taxi.client.Task.MyORGTask.java
 * @Author 严旭文
 * @Date 2016-3-31 上午10:43:11
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 * 获取所在的顶级机构
 */
public class MyORGTask{
	private Activity context;
	public static MyORGTask instance;
	public ORGTask mORGTask;
	public interface OnORGListener {
		/**
		 *获取所在的顶级机构
		 */
		public void onORGFinish(Official_ORG mOfficial_ORG);
	}

	static OnORGListener mOnORGListener = null;

	public static void setOnORGListener(OnORGListener l) {
		mOnORGListener = l;
	}
	public static MyORGTask getInstance(Activity context,String member_id) {
		instance = new MyORGTask(context,member_id);
		return instance;
	}
	public MyORGTask(Activity context,String member_id) {
		this.context = context;
		getORG(member_id);
	
	}
	/**
	 * 获取用户机构
	 */
	public void getORG(String member_id) {
		Official_ORGBuild mOfficial_ORGBuild=new Official_ORGBuild(context);
		mOfficial_ORGBuild.opuid=MyApplication.getInstance().getUid();
		mOfficial_ORGBuild.member_id=MyApplication.getInstance().getUid();
		ORGTask mORGTask=new ORGTask(context, mOfficial_ORGBuild);
		mORGTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	private class ORGTask extends BaseAsyncTask {

		private Official_ORGBuild mOfficial_ORGBuild;

		public ORGTask(Activity context, Official_ORGBuild mOfficial_ORGBuild) {
			super(context);
			this.mOfficial_ORGBuild = mOfficial_ORGBuild;
		}

		@Override
		public void onSuccess(Object object) {
			if (object != null) {
				Official_ORG mOfficial_ORG=(Official_ORG)object;
				if(mOfficial_ORG!=null){
					if (mOnORGListener != null) {
						mOnORGListener.onORGFinish(mOfficial_ORG);
					}
				}else{
					ToastUtil.showToast(context, R.string.no_network);
					if (mOnORGListener != null) {
						mOnORGListener.onORGFinish(null);
					}
				}
				
			} else {
				ToastUtil.showToast(context, R.string.no_network);
				if (mOnORGListener != null) {
					mOnORGListener.onORGFinish(null);
				}
			}
		}

		@Override
		public void onFailed(int status, String msg) {
			ToastUtil.showToast(context, R.string.no_network);
			if (mOnORGListener != null) {
				mOnORGListener.onORGFinish(null);
			}
	
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mOfficial_ORGBuild).getJson();
			return new Official_ORGNet(context, json);
		}
	}

}
